package com.qf.servlet;

import com.qf.pojo.Product;
import com.qf.service.ProductService;
import com.qf.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 加载首页的控制器
 */
@WebServlet("/index")
public class IndexServlet extends BaseServlet {

    /**
     * 加载首页的方法  获取首页中最新商品和热门商品列表
     * @param request 请求对象
     * @param response 响应对象
     */
    public void index(HttpServletRequest request,HttpServletResponse response)
            throws ServletException, IOException {




        //调用业务接口
        ProductService productService = new ProductServiceImpl() ;
        //获取最新商品
        List<Product> newList = productService.getNewProducts();
        //获取热门商品
        List<Product> hotList = productService.getHotProducts();


        //System.out.println("index方法进来了...");

        //存储request域中
        request.setAttribute("newList",newList);
        request.setAttribute("hotList",hotList);
        //请求转发"/jsp/index.jsp"
        request.getRequestDispatcher("/jsp/index.jsp").forward(request,response);
    }

}
